/*
 * Copyright (c) 2023, 2024,yzc.cn All rights reserved.
 *
 */
package com.by.mq.consumer;

import com.by.mapper.PurApplicationDetailsMapper;
import com.by.mapper.PurApplicationMapper;
import com.by.mapper.PurInquiryMapper;
import com.by.pojo.PurInquiry;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

/**
 * <p>Project: erp-cloud-api - StatusMQConsumer</p>
 * <p>Powered by yzc On 2024-01-11 19:24:43</p>
 * <p>描述：<p>
 *
 * @author yzc [yzc0415@126.com]
 * @version 1.0
 * @since 17
 */
@Component
public class StatusMQConsumer {


    @Autowired
    RabbitTemplate rabbitTemplate;

    @Autowired
    PurInquiryMapper purInquiryMapper;

    @Autowired
    PurApplicationDetailsMapper purApplicationDetailsMapper;

    @RabbitListener(queues = {"valuationStatusQueue"})
    public void handlerValuation(String inquiryCode,Message message,Channel channel) throws IOException {
        int rs = purInquiryMapper.updateStatusInt(inquiryCode);
        if (rs>0){
            //更新成功
            //手动应带
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
            Map<String,String> map = purInquiryMapper.queryCodeMap(inquiryCode);
          int i =  purApplicationDetailsMapper.updateStatus(map.get("detailsId"));
          if (i > 0){
              purApplicationDetailsMapper.updateInquiry(map.get("detailsId"),map.get("source"));
          }
            System.out.println(map);
        }else {
            //更新失败
            //拒绝消息
            channel.basicReject(message.getMessageProperties().getDeliveryTag(),false);
        }



    }

}
